
import Common from './common';

export default class PaginationAction extends Common {
    constructor(comp) {
        super();
        this.comp = comp;
    }

    // 翻页
    turnPage = (page) => {
        const {
            props: {
                dispatch,
                sca
            }
        } = this.comp;

        let nPageInfo = {
            ...sca.pageInfo,
            pageIndex: page
        };

        dispatch({
            type: 'sca/handleParamsByKey',
            payload: {
                pageInfo: nPageInfo
            }
        });

        this.pubSub.publish('getMainTable', {
            pageInfo: this.deepCopy(nPageInfo)
        });
    }

    // 切换页面条数
    changePageSize = (pageSize) => {
        const {
            props: {
                dispatch,
                sca
            }
        } = this.comp;

        let nPageInfo = {
            ...sca.pageInfo,
            pageSize: pageSize
        };

        dispatch({
            type: 'sca/handleParamsByKey',
            payload: {
                pageInfo: nPageInfo
            }
        });

        this.pubSub.publish('getMainTable', {
            pageInfo: this.deepCopy(nPageInfo)
        });
    }
}